﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.IsoParametricCurves.CApIsoParametricCurveFaceValidator
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.Collections.ObjectModel;
using System.Resources;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.PrivateImplementationDetails;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.IsoParametricCurves;

internal class CApIsoParametricCurveFaceValidator : ITxValidator
{
  private string invalidObjMsg;
  private string missingObjMsg;

  public CApIsoParametricCurveFaceValidator()
  {
    ResourceManager resourceManager = new ResourceManager("DnProcessSimulateCommands.IsoParametricCurves.IsoParametricCurvesStringTable", this.GetType().Assembly);
    this.invalidObjMsg = resourceManager.GetString("INVALID_OBJECT");
    this.missingObjMsg = resourceManager.GetString("MISSING_OBJECT");
  }

  private bool ValidFaceObject(ITxObject obj)
  {
    bool flag = false;
    if (obj != null && obj is TxExactGeometryFace exactGeometryFace && !(((TxFace) exactGeometryFace).OwnerComponent is TxViewCamera))
      flag = true;
    return flag;
  }

  public ITxObject GetObject(string str)
  {
    ITxObject itxObject1 = (ITxObject) null;
    if (!string.IsNullOrEmpty(str))
    {
      TxObjectList objectsByName = TxApplication.ActiveDocument.GetObjectsByName(str);
      if (objectsByName != null && ((Collection<ITxObject>) objectsByName).Count > 0)
      {
        foreach (ITxObject itxObject2 in (Collection<ITxObject>) objectsByName)
        {
          if (this.ValidFaceObject(itxObject2))
          {
            itxObject1 = itxObject2;
            break;
          }
        }
      }
    }
    return itxObject1;
  }

  public string GetText(ITxObject obj)
  {
    string text = (string) null;
    try
    {
      text = obj.Name;
    }
    catch (Exception ex)
    {
    }
    return text;
  }

  public bool IsValidObject(ITxObject obj, out string errorMessage)
  {
    bool flag = false;
    errorMessage = string.Empty;
    if (obj != null)
    {
      flag = this.ValidFaceObject(obj);
      if (!flag)
        errorMessage = this.invalidObjMsg;
    }
    else
      errorMessage = this.missingObjMsg;
    return flag;
  }

  public bool IsValidText(string text, out string errorMessage)
  {
    return this.IsValidObject(this.GetObject(text), out errorMessage);
  }
}
